<template>
  <basic-container>
    <basic-header title="商户列表" />
    <apply-table ref="table" :action="action">
      <template slot-scope="{ row }" slot="applyMenu">
        <el-button plain :type="row.isPutAway ? 'warning' : 'success'" size="small" :icon="`el-icon-${row.isPutAway ? 'download' : 'upload2'}`"
          @click.stop="handleChange(row)">{{row.isPutAway ? '下架' : '上架'}}</el-button>
      </template>
    </apply-table>
  </basic-container>
</template>
<script>
import ApplyTable from "@/components/ApplyTable";
import actionTypes from "@/const/action";
import { PromiseShopPutAway } from "@/api/config";
export default {
  name: "shop",
  components: { ApplyTable },
  data() {
    return {
      action: actionTypes.MERCHANT_LIST
    };
  },
  methods: {
    handleChange(row) {
      const type = row.isPutAway ? "下架" : "上架";
      this.$confirm(`确认${type}吗？`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        PromiseShopPutAway(row.id, !row.isPutAway)
          .then(() => {
            this.$message({
              type: "success",
              message: `已成功${type}`
            });
            this.$refs.table.RefreshData();
          })
          .catch(error => {
            this.$message({
              type: "error",
              message: error.message || String(error)
            });
          });
      });
    }
  }
};
</script>

